get last path segment of url in javascript

62

get last path segment of url in javascript -

const last_segment = window.location.pathname.split('/').pop();

javascript get last url segment -

console.log(this.href.substring(this.href.lastIndexOf('/') + 1));

Comments

Submit
0 Comments